﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace FitCalc
{
    public class RunningTime
    {
        private int minutes, seconds;
        public RunningTime()
        {
            this.Minutes = 0;
            this.Seconds = 0;
        }
        public RunningTime(int Minutes, int Seconds)
        {
            this.Minutes = Minutes;
            this.Seconds = Seconds;
        }

        public RunningTime(string Minutes, string Seconds)
        {
            if (Minutes != null && Minutes.Length > 0)
                this.Minutes = int.Parse(Minutes);
            else
                this.Minutes = 0;
            this.Seconds = int.Parse(Seconds);
        }

        public int Minutes
        {
            get
            {
                return minutes;
            }
            set
            {
                minutes = value;
            }
        }

        public int Seconds
        {
            get
            {
                return seconds;
            }
            set
            {
                seconds = value;
            }
        }
    }
    public static class RunningCalc
    {
        public static double PaceToSpeed(RunningTime rt)
        {
            return Math.Round(60 / ((double)rt.Minutes + ((double)rt.Seconds / 60)), 2);
        }
        public static RunningTime SpeedToPace(double speed)
        {
            RunningTime rt = new RunningTime();
            if (speed > 0)
            {
                double paceTemp = 60 / speed;
                rt.Minutes = (int)Math.Truncate(paceTemp);
                rt.Seconds = (int)Math.Truncate((paceTemp - Math.Truncate(paceTemp)) * 60);
            }
            else
            {
                rt.Minutes = 0;
                rt.Seconds = 0;
            }
            return rt;
        }

    }
}